﻿Imports UCBase
Imports System.Drawing

Public Class BaseMonitor
    Implements I_LoadSave
    Implements I_EditMode
    Private BackPic As New BackgroundCreator
    Private Mover As New Mover
    Private M_Edit As Boolean = True
    Private WithEvents ImageInput As I_ImageExchange
    Private PT As Integer
    Private AC As Integer = 0
    Private AV As Integer = 0
    Private FPS As Integer

    Private Sub Monitor_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Width = 375
        Me.Height = 250
    End Sub

    Public Sub New()
        InitializeComponent()
        Me.BackgroundImage = BackPic.CreatePic(Me.Width, Me.Height)
        Mover.Connect(Me)
    End Sub
    Public Property EditMode() As Boolean
        Get
            Return M_Edit
        End Get
        Set(ByVal value As Boolean)
            M_Edit = value
            Mover.EditMode = value
        End Set
    End Property
    Private Sub Socket2_Connect() Handles Socket2.Connect
        If Socket2.SocketType = Socket.Socket_Type.Image Then
            Dim S As Socket = Socket2.Remote
            ImageInput = S.Parent
        End If
    End Sub

    Private Sub ImageInput_ImageOut(ByVal Image As System.Drawing.Bitmap) Handles ImageInput.ImageOut1
        PictureBox1.Image = Image
        Dim TBMP As New Bitmap(Image)
        Dim G As Graphics = Graphics.FromImage(TBMP)
        Dim CT As Integer = My.Computer.Clock.TickCount
        Dim C As Integer = CT - PT
        PT = CT
        If C > 0 Then
            AV = AV + (1000 / C)
            AC = AC + 1
            If AC = 10 Then
                AC = 0
                FPS = AV / 10
                AV = 0
            End If
        End If
        Dim S As String = Image.Width.ToString & " x " & Image.Height.ToString & " - " & Image.PixelFormat.ToString.Substring(6) & " " & FPS.ToString("00") & " FPS"
        G.DrawString(S, Me.Font, Brushes.White, 10, 10)
        PictureBox1.Image = TBMP
        'TBMP.Dispose()
    End Sub

    Private Sub Socket2_Disconnected() Handles Socket2.Disconnected
        If Socket2.SocketType = Socket.Socket_Type.Image Then
            ImageInput = Nothing
        End If
        Socket2.SocketType = Socket.Socket_Type.Universal
    End Sub
    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return ""
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub

    Public Sub SetEditMode(ByVal Mode As UCBase.Diagram.EditMode) Implements UCBase.I_EditMode.SetEditMode

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub Socket2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Socket2.Click

    End Sub
End Class
